package com.onec.service.customer.service.api;

import com.onec.service.api.dto.request.customer.AgentInfoReq;
import com.onec.service.api.dto.response.customer.AgentInfoResp;
import com.onec.service.api.service.customer.AgentInfoApiService;
import com.onec.service.api.utils.ValidatorUtils;
import com.onec.service.api.utils.group.AgentParamGroup;
import com.onec.service.customer.entity.agent.AgentBusiness;
import com.onec.service.customer.entity.agent.AgentInfo;
import com.onec.service.customer.entity.agent.AgentKey;
import com.onec.service.customer.service.base.BaseAgentInfoServiceImpl;
import org.apache.dubbo.config.annotation.DubboService;

/**
 * @author onec
 * @see com
 */
@DubboService(version = "1.0.1")
public class AgentInfoApiServiceImpl extends BaseAgentInfoServiceImpl implements AgentInfoApiService {


    @Override
    public AgentInfoResp getAgent(AgentInfoReq agentInfoReq) {

        ValidatorUtils.validateEntity(agentInfoReq, AgentParamGroup.class);

        AgentInfo agentInfo = agentInfoService.getAvailableAgent(agentInfoReq.getAgentCode());
        AgentKey agentKey = agentInfoService.getAgentKey(agentInfo.getId());
        return respAgentInfo(agentInfo, agentKey);
    }

    @Override
    public AgentInfoResp getAgentBusiness(AgentInfoReq agentInfoReq) {
        ValidatorUtils.validateEntity(agentInfoReq, AgentParamGroup.class);
        AgentInfo agentInfo = agentInfoService.getAvailableAgent(agentInfoReq.getAgentCode());

        AgentBusiness agentBusiness = agentInfoService.getAvailableAgentBus(agentInfo.getId(), agentInfoReq.getBusinessNo());
        return respAgentBusInfo(agentInfo, agentBusiness);
    }


}
